#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    resize(260,90);
    QGridLayout *layout=new QGridLayout(this);
    lb1=new QLabel(this);
    lb1->setText("自定义消息框");
    lb2=new QLabel(this);
    lb2->setText("未测试状态");
    bt1=new QPushButton(this);
    bt1->setText("测试操作");
    layout->addWidget(lb1,0,0);
    layout->addWidget(bt1,0,1);
    layout->addWidget(lb2,1,0);

    connect(bt1,&QPushButton::clicked,this,&Widget::mySingnal);

}

Widget::~Widget()
{
    delete ui;
}

void Widget::mySingnal()
{
    QMessageBox  cMsgBox;
    cMsgBox.setWindowTitle("铃声教育消息框");

    //添加按钮
    QPushButton *yes=cMsgBox.addButton("Yes",QMessageBox::DestructiveRole);
    QPushButton *no=cMsgBox.addButton("no",QMessageBox::ActionRole);
    cMsgBox.setIconPixmap(QPixmap("D:\\job\\qt\\work\\me\\day2\\MyCustomQMessagebox1\\lspng.png"));
    cMsgBox.exec();

    //判断用户按下按钮
    if(cMsgBox.clickedButton()==yes)
    {
        lb2->setText("用户点击YES按钮");
    }
    else if(cMsgBox.clickedButton()==no)
    {
        lb2->setText("用户点击NO按钮");
    }



}

